package com.yh.hljapp.api;


import com.yh.hljapp.common.StringUtils;

import java.io.IOException;

import retrofit2.adapter.rxjava.HttpException;


/**
 * Created by imyar on 2016/6/15.
 */
public class ErrorHandler {

    public static String handle(Throwable throwable) {
        if (throwable instanceof HttpException) {
            HttpException error = (HttpException) throwable;
            try {
                String errms=error.response().errorBody().string().toString().trim();
                if (StringUtils.isEmpty(errms)){
                    errms=throwable.getMessage();
                }
                return errms;
//                return new Gson().fromJson(errms
//
//              ,
//                        BodyResponse.class);
            } catch (IOException e) {
                return throwable.getMessage();
            }
        } else {
            return throwable.getMessage();
        }
    }
}
